﻿using System;
using System.Collections.Generic;
using System.Text;
using NLBS.Entity;
using System.Globalization;
using NLBS.Framework;

namespace NLBS.Data.Business
{
    /// <summary>
    /// 用于表情图标缓存操作
    /// </summary>
    public class SmileData:CommonBase
    {
        private static readonly string SmileKey = "SmileKey";

        public static List<Smile> GetSmile()
        {
            ContentCache cache = ContentCache.Instantiate();
            List<Smile> lists = (List<Smile>)cache[SmileKey];
            if (lists == null)
            {
                lists = new List<Smile>(DbProvider.Instance().GetSmile());
                if (lists != null)
                {
                    cache.Insert(SmileKey, lists, CacheDuration.Long);
                }
            }
            return lists;
        }

        public static List<Smile> SmileList
        {
            get
            {
                return GetSmile();
            }
        }

        public static Smile GetSmileByID(int id)
        {
            return SmileList.Find(delegate(Smile s)
            {
                return s.SmID == id;
            });
        }
        public static void InsertSmile(Smile sm)
        {
            int result = DbProvider.Instance().InsertSmile(sm);
            sm.SmID = result;
            SmileList.Add(sm);
        }

        public static void UpdateSmile(Smile sm)
        {
            DbProvider.Instance().UpdateSmile(sm);
            //Smile updateSm = GetSmileByID(sm.SmID);
            //IList<Smile> list = GetSmile();
            //list[list.IndexOf(updateSm)] = sm;

        }

        public static void DeleteSmile(int smID)
        {
            DbProvider.Instance().DeleteSmile(smID);
            Smile sb=GetSmileByID(smID);
            SmileList.Remove(sb);
        }
    }
}
